package TUILayer;
import java.util.Scanner;
import ControlLayer.DVDCtr;
/**
 * @author (DM80 Group 5, Anders, Michael, Jesper, Lars og Kenni) 
 * @version (16/11-2012)            
 */

public class DvdUI
{
    private DVDCtr dvdCtr;//DVD UI must know the DVD controller 
    
    public DvdUI()
    {
        dvdCtr = new DVDCtr();    
    }
    
    public void start(DVDCtr ctr)
    {
        dvdCtr= ctr;
        dvdMenu();
    }
    
    public void start()
    {
        dvdMenu();
    }
    
    public void dvdMenu()
    {   
        boolean exit = false;
        while(!exit)
        {
            //show menu and return the user's choise
            int choise =   writeDVDMenu();
            if (choise == 1)
            {
                findDVD();
            }
            else{
                if(choise == 2){
                   createDVD();
                }
                else{
                    if(choise == 3){
                        createCopy();
                    }
                    else{
                        if(choise == 4){
                             deleteDVD();
                        }
                        else{
                            if(choise == 5){
                                listAllDvds();
                            }
                            else{
                                exit = true;
                            }//end else
                        }//end else
                    }//end else
                }//end else
            }//end else
            
        }//end while
    }
    private int writeDVDMenu()
    {
           // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** DVD Menu ***");
            System.out.println(" (1) Show DVD information");
            System.out.println(" (2) Create DVD description");
            System.out.println(" (3) Create DVD sample");
            System.out.println(" (4) Delete DVD");
            System.out.println(" (5) Show current DVD list");
            System.out.println(" (6) Return");
            System.out.print("\n Make your choise: ");
            
            int choise = keyboard.nextInt();
            return choise;
    }
    
    private int inputDVDNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Type DVD number: ");
        int no = keyboard.nextInt();
        return no;
    }
    
    private int inputSampleSerial()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Type Sample Serial nr: ");
        int serialNr = keyboard.nextInt();
        return serialNr;
    }
    
    private String inputSampleAcquireDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Type Sample Acquire Date: " );
        String acquireDate = keyboard.nextLine();
        return acquireDate;
    }
    
    private double inputSampleAcquirePrice()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Type Sample Acquire Price: " );
        double acquirePrice = keyboard.nextDouble();
        return acquirePrice;
    }
    
    private String inputTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }
    
    private String inputArtist()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Type DVD artist: " );
        String artist = keyboard.nextLine();
        return artist;
    }
    
    private String inputReleaseDate()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Type DVD Release Date: " );
        String releaseDate = keyboard.nextLine();
        return releaseDate;
    }
    
    private String inputDescription()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Type DVD Description: " );
        String description = keyboard.nextLine();
        return description;
    }
    
    private int inputCopyNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println(" Type the copy number: ");
        int no = keyboard.nextInt();
        return no;
    }
    
    private void pause()
    {
        Scanner keyboard = new Scanner(System.in);
        String vent = keyboard.nextLine();
    }
  
    private void findDVD()
    {     
        int _id = inputDVDNo();
        
        System.out.println(dvdCtr.findDVD(_id));
        
        pause();
    }
    
    private void createDVD()
    {
        System.out.println();
        System.out.println(" Opret ny DVD:");
        
        int _id = inputDVDNo();
        String _title = inputTitle();
        String _artist = inputArtist();
        String _releaseDate = inputReleaseDate();
        String _description = inputDescription();
        
        dvdCtr.createDVD(_id, _title, _artist, _releaseDate, _description);
        
        System.out.println();
        System.out.println(" " + _title + " has been created!");
        
        pause();
    }
    
    private void createCopy()
    {
        int _dvdId = inputDVDNo();
        int _sampleSerialNr = inputSampleSerial();
        String _sampleAcquireDate = inputSampleAcquireDate();
        double _sampleAcquirePrice = inputSampleAcquirePrice();
        
        boolean success = dvdCtr.createSample(_dvdId, _sampleSerialNr, _sampleAcquireDate, _sampleAcquirePrice);
        
        if(success == true)
        {
            System.out.println(" " + _sampleSerialNr + " has been added to dvd with id: " + _dvdId);
        }
        else
        {
            System.out.println(" " + _dvdId + " could not be found!");   
        }
        
        pause();
    }
    
    private void deleteDVD()
    {
        int _id = inputDVDNo();
        
        if(dvdCtr.deleteDVD(_id))
        {
            System.out.println(" " + _id + " has been removed!");
        }
        else
        {
            System.out.println(" " + _id + " could not be found!");   
        }
        
        pause();
    }
    
    private void listAllDvds()
    {
        System.out.println(dvdCtr.printAllDvds());
        
        pause();
    }
}